package com.ds.controller;

import com.ds.exception.MyException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.time.LocalDateTime;
import java.util.Arrays;

/**
 * @program: SpringBoot
 * @description:
 * @author: Dawson.Zhang
 * @create: 2020-04-18
 **/
@Controller
public class HelloController {
    @ResponseBody
    @RequestMapping("/hello")
    public String hello(String user) {
        if ("aaa".equals(user)){
            throw new MyException();
        }
        return "Hello World";
    }

    @RequestMapping("/success")
    public String success(Model model) {
        model.addAttribute("hi", "<span style='color:red'>你好<span>");
        model.addAttribute("users", Arrays.asList("zhangsan", "李斯特", "王武特"));
        model.addAttribute("date", System.currentTimeMillis());
        return "success";
    }
}
